<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/11/15
  Time: 9:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script>
        function sendAjax(){
            //1 创建 ajax对象
            let xhr = new XMLHttpRequest();


            //2发起请求
            let method = "GET";
            let url = "http://localhost:8080/web05/ajax";
            // false  同步的方法
            // let async = false;
            // true 异步的方法
            let async = true;


            xhr.onreadystatechange = function(){
                console.log("xhr.readyState",xhr.readyState);
                console.log("xhr.status",xhr.status);
                console.log("\r\n\r\n");
               if( xhr.readyState==4 && xhr.status==200){
                   alert(xhr.responseText);
               }
            }

            xhr.open(method,url,async);
            xhr.send();

            //3获取结果
            //同步的结果
            // alert(xhr.responseText);



            //4 使用结果
        }


    </script>
</head>
<body>



<button onclick="sendAjax()">请求</button>
<button onclick="console.log('按钮被点击....')">测试按钮</button>







</body>
</html>
